﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Vuforia
{
    public class CameraSetting : MonoBehaviour
    {

        private bool mIsFlashOpend;
        private bool mIsFrontCamera;

        // Use this for initialization
        void Start()
        {
            var vuforia = VuforiaARController.Instance;
            vuforia.RegisterVuforiaStartedCallback(OnVuforiaStarted);
            vuforia.RegisterOnPauseCallback(OnPaused);
        }

        // Update is called once per frame
        void Update()
        {

        }

        private void OnVuforiaStarted()
        {
            CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
            ToastUtil.showToast("OnVuforiaStarted");
        }

        private void OnPaused(bool isPaused)
        {

        }

        public void OnFocusModeClick()
        {
            CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_TRIGGERAUTO);
        }

        //切换为前置摄像头
        public void SwitchCameraDirection()
        {
            if (!mIsFrontCamera)
            {
                //SwitchCameraDirection(CameraDevice.CameraDirection.CAMERA_FRONT);
            }
            else
            {
                //SwitchCameraDirection(CameraDevice.CameraDirection.CAMERA_BACK);
            }
            mIsFrontCamera = !mIsFrontCamera;

            ToastUtil.showToast("SwitchFrontCameraDirection mIsFrontCamera=" + mIsFrontCamera);
        }

        //切换摄像头
        //public void SwitchCameraDirection(CameraDevice.CameraDirection direction)
        //{
        //    CameraDevice.Instance.Stop();
        //    CameraDevice.Instance.Deinit();

        //    CameraDevice.Instance.Init(direction);
        //    CameraDevice.Instance.Start();
        //}

        public void FlashTourch()
        {
            if (!mIsFlashOpend)
            {
                CameraDevice.Instance.SetFlashTorchMode(mIsFlashOpend);
            }
            mIsFlashOpend = !mIsFlashOpend;
            ToastUtil.showToast("FlashTourch mIsFlashOpend = " + mIsFlashOpend);
        }
    }
}